Passed
Push — development ( e131c7...d0a4d7 )
by Peter
05:27 queued 13s
created

main.ts ➔ bootstrap   B

Complexity

Conditions 7

Size

Total Lines 37
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 30
dl 0
loc 37
rs 7.76
c 0
b 0
f 0
1
import { NestFactory } from '@nestjs/core';
2
import { AppModule } from './app.module';
3
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
4
import { ValidationPipe } from '@nestjs/common';
5
6
async function bootstrap() {
7
  const app = await NestFactory.create(AppModule);
8
9
  app.useGlobalPipes(
10
    // Note global validation pipe
11
    new ValidationPipe({
12
      whitelist: true,
13
      forbidNonWhitelisted: true,
14
      transform: true,
15
    }),
16
  );
17
18
  const config = new DocumentBuilder()
19
    .setTitle('Svenska Elsparkcyklar API')
20
    .setDescription('API for bike rental service')
21
    .setVersion('1.0')
22
    .addBearerAuth()
23
    .build();
24
25
  app.enableCors({
26
    origin: [
27
      'http://localhost:5173', // Frontend
28
      'http://localhost:1337', // kundapp
29
      'http://localhost:5174', // bike-app
30
      `http://localhost:${process.env.PORT ?? 3000}`, // Swagger UI
31
    ],
32
    methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS'],
33
    allowedHeaders: ['Content-Type', 'Authorization', 'Accept'],
34
    credentials: true,
35
  });
36
37
  const document = SwaggerModule.createDocument(app, config);
38
  SwaggerModule.setup('api', app, document);
39
40
  const port = process.env.PORT ?? 3000;
41
  await app.listen(port ?? 3000, '0.0.0.0');
42
}
43
bootstrap();
44